#include <iostream>
#include <memory>
#include <vector>
using std::cout;
using std::endl;
using std::unique_ptr;
using std::vector;

class Point
{
public:
    Point(int x,int y)
    : _ix(x)
    , _iy(y)
    {}

    void print() const{
        cout << "(" << _ix
            << "," << _iy
            << ")" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test1(){
    unique_ptr<Point> up(new Point(1,2));
    (*up).print();

    unique_ptr<Point> up2(new Point(7,8));
    vector<unique_ptr<Point>> vec;
    vec.push_back(unique_ptr<Point>(new Point(8,5)));
    //up原本管理的资源的管理权移交给了vector的第二个元素
    //up失去了对Point的管理权
    vec.push_back(std::move(up));
    vec[0]->print();
    vec[1]->print();
    /* (*up).print(); */

}


void test0(){
    unique_ptr<int> up(new int(10));
    //unique_ptr不允许进行复制赋值
    /* unique_ptr<int> up2(up); */

    unique_ptr<int> up3(new int(10));
    /* up3 = up; */

    int * p = new int(1);
    unique_ptr<int> up4(p);
    cout << *up4 << endl;
    cout << *p << endl;
    /* delete p; */
}



int main(void){
    test1();
    return 0;
}
